home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 June / MacFormat 25.iso / Shareware City / Developers / Glypha III Src Folder / Code ƒ / Play.c < prev    next >
Encoding:
Text File  |  1995-02-03  |  22.3 KB  |  1,044 lines  |  [TEXT/MPCC]

  1.  
  2. //============================================================================
  3. //----------------------------------------------------------------------------
  4. //                                    Play.c
  5. //----------------------------------------------------------------------------
  6. //============================================================================
  7.  
  8.  
  9. #include "Externs.h"
  10.  
  11.  
  12. #define kFlapImpulse            48
  13. #define kGlideImpulse            12
  14. #define kAirResistance            2
  15. #define kMaxHVelocity            192
  16. #define kMaxVVelocity            512
  17. #define kNumLightningStrikes    5
  18.  
  19.  
  20. void SetUpLevel (void);
  21. void ResetPlayer (Boolean);
  22. void OffAMortal (void);
  23. void DoCommandKey (void);
  24. void GetPlayerInput (void);
  25. void HandlePlayerIdle (void);
  26. void HandlePlayerFlying (void);
  27. void HandlePlayerWalking (void);
  28. void HandlePlayerSinking (void);
  29. void HandlePlayerFalling (void);
  30. void HandlePlayerBones (void);
  31. void MovePlayer (void);
  32. void CheckTouchDownCollision (void);
  33. void CheckPlatformCollision (void);
  34. void KeepPlayerOnPlatform (void);
  35. void CheckLavaRoofCollision (void);
  36. void SetAndCheckPlayerDest (void);
  37. void HandleLightning (void);
  38. void FinishLightning (void);
  39. void HandleCountDownTimer (void);
  40. void CheckHighScore (void);
  41.  
  42.  
  43. playerType    thePlayer;
  44. enemyType    theEnemies[kMaxEnemies];
  45. KeyMap        theKeys;
  46. Rect        platformRects[6], touchDownRects[6], enemyRects[24];
  47. Rect        enemyInitRects[5];
  48. long        theScore, wasTensOfThousands;
  49. short        numLedges, beginOnLevel, levelOn, livesLeft, lightH, lightV;
  50. short        lightningCount, numEnemies, countDownTimer;
  51. Boolean        playing, pausing, flapKeyDown, evenFrame;
  52. Boolean        doEnemyFlapSound, doEnemyScrapeSound;
  53.  
  54. extern    handInfo    theHand;
  55. extern    prefsInfo    thePrefs;
  56. extern    Rect        playerRects[11], mainWindowRect;
  57. extern    short        numUpdateRects1, numUpdateRects2, numOwls;
  58. extern    Boolean        quitting, openTheScores;
  59.  
  60.  
  61. //==============================================================  Functions
  62. //--------------------------------------------------------------  InitNewGame
  63.  
  64. void InitNewGame (void)
  65. {
  66.     countDownTimer = 0;
  67.     numLedges = 3;
  68.     beginOnLevel = 1;
  69.     levelOn = 0;
  70.     livesLeft = kInitNumLives;
  71.     theScore = 0L;
  72.     playing = TRUE;
  73.     pausing = FALSE;
  74.     evenFrame = TRUE;
  75.     wasTensOfThousands = 0L;
  76.     numOwls = 4;
  77.     
  78.     numUpdateRects1 = 0;
  79.     numUpdateRects2 = 0;
  80.     
  81.     InitHandLocation();
  82.     theHand.mode = kLurking;
  83.     
  84.     SetUpLevel();
  85.     
  86.     DumpBackToWorkMap();
  87.     
  88.     UpdateLivesNumbers();
  89.     UpdateScoreNumbers();
  90.     UpdateLevelNumbers();
  91.     
  92.     GenerateEnemies();
  93.     ResetPlayer(TRUE);
  94. }
  95.  
  96. //--------------------------------------------------------------  SetUpLevel
  97.  
  98. void SetUpLevel (void)
  99. {
  100.     short        wasLedges, waveMultiple;
  101.     
  102.     KillOffEye();
  103.     
  104.     wasLedges = numLedges;
  105.     waveMultiple = levelOn % 5;
  106.     
  107.     switch (waveMultiple)
  108.     {
  109.         case 0:
  110.         numLedges = 5;
  111.         break;
  112.         
  113.         case 1:
  114.         numLedges = 6;
  115.         break;
  116.         
  117.         case 2:
  118.         numLedges = 5;
  119.         break;
  120.         
  121.         case 3:
  122.         numLedges = 3;
  123.         break;
  124.         
  125.         case 4:
  126.         numLedges = 6;
  127.         break;
  128.     }
  129.     
  130.     if (wasLedges != numLedges)
  131.         DrawPlatforms(numLedges);
  132.     
  133.     FlashObelisks(TRUE);
  134.     
  135.     GenerateLightning(320, 429);    // platform 0
  136.     StrikeLightning();
  137.     LogNextTick(2);
  138.     WaitForNextTick();
  139.     StrikeLightning();
  140.     
  141.     GenerateLightning(95, 289);        // platform 1
  142.     StrikeLightning();
  143.     LogNextTick(2);
  144.     WaitForNextTick();
  145.     StrikeLightning();
  146.     
  147.     GenerateLightning(95, 110);        // platform 3
  148.     StrikeLightning();
  149.     LogNextTick(2);
  150.     WaitForNextTick();
  151.     StrikeLightning();
  152.     
  153.     GenerateLightning(320, 195);    // platform 5
  154.     StrikeLightning();
  155.     LogNextTick(2);
  156.     WaitForNextTick();
  157.     StrikeLightning();
  158.     
  159.     GenerateLightning(545, 110);    // platform 4
  160.     StrikeLightning();
  161.     LogNextTick(2);
  162.     WaitForNextTick();
  163.     StrikeLightning();
  164.     
  165.     GenerateLightning(545, 289);    // platform 2
  166.     StrikeLightning();
  167.     LogNextTick(2);
  168.     WaitForNextTick();
  169.     StrikeLightning();
  170.     
  171.     FlashObelisks(FALSE);
  172.     PlayExternalSound(kLightningSound, kLightningPriority);
  173.     
  174.     UpdateLevelNumbers();
  175. }
  176.  
  177. //--------------------------------------------------------------  ResetPlayer
  178.  
  179. void ResetPlayer (Boolean initialPlace)
  180. {
  181.     short        location;
  182.     
  183.     thePlayer.srcNum = 5;
  184.     thePlayer.frame = 320;
  185.     
  186.     if (initialPlace)
  187.         location = 0;
  188.     else
  189.         location = RandomInt(numLedges);
  190.     
  191.     switch (location)
  192.     {
  193.         case 0:
  194.         thePlayer.h = 296 << 4;        // bottom center
  195.         thePlayer.v = 377 << 4;
  196.         break;
  197.         
  198.         case 1:
  199.         thePlayer.h = 102 << 4;
  200.         thePlayer.v = 237 << 4;
  201.         break;
  202.         
  203.         case 2:
  204.         thePlayer.h = 489 << 4;
  205.         thePlayer.v = 237 << 4;
  206.         break;
  207.         
  208.         case 3:
  209.         thePlayer.h = 102 << 4;
  210.         thePlayer.v = 58 << 4;
  211.         break;
  212.         
  213.         case 4:
  214.         thePlayer.h = 489 << 4;
  215.         thePlayer.v = 58 << 4;
  216.         break;
  217.         
  218.         case 5:
  219.         thePlayer.h = 296 << 4;
  220.         thePlayer.v = 143 << 4;
  221.         break;
  222.     }
  223.     
  224.     thePlayer.dest = playerRects[thePlayer.srcNum];
  225.     ZeroRectCorner(&thePlayer.dest);
  226.     OffsetRect(&thePlayer.dest, thePlayer.h >> 4, thePlayer.v >> 4);
  227.     thePlayer.wasDest = thePlayer.dest;
  228.     
  229.     thePlayer.hVel = 0;
  230.     thePlayer.vVel = 0;
  231.     thePlayer.facingRight = TRUE;
  232.     thePlayer.flapping = FALSE;
  233.     thePlayer.wrapping = FALSE;
  234.     thePlayer.clutched = FALSE;
  235.     thePlayer.mode = kIdle;
  236.     if (lightningCount == 0)
  237.     {
  238.         lightH = thePlayer.dest.left + 24;
  239.         lightV = thePlayer.dest.bottom - 24;
  240.         lightningCount = kNumLightningStrikes;
  241.     }
  242. }
  243.  
  244. //--------------------------------------------------------------  OffAMortal
  245.  
  246. void OffAMortal (void)
  247. {
  248.     livesLeft--;
  249.     
  250.     if (livesLeft > 0)
  251.     {
  252.         ResetPlayer(FALSE);
  253.         UpdateLivesNumbers();
  254.     }
  255.     else
  256.     {
  257.         playing = FALSE;
  258.     }
  259. }
  260.  
  261. //--------------------------------------------------------------  DoCommandKey
  262.  
  263. void DoCommandKey (void)
  264. {
  265.     if (BitTst(&theKeys, kEKeyMap))
  266.     {
  267.         playing = FALSE;
  268.     }
  269.     else if (BitTst(&theKeys, kPKeyMap))
  270.     {
  271.         pausing = TRUE;
  272.         MenusReflectMode();
  273.         DumpMainToWorkMap();
  274.     }
  275.     else if (BitTst(&theKeys, kQKeyMap))
  276.     {
  277.         playing = FALSE;
  278.         quitting = TRUE;
  279.     }
  280. }
  281.  
  282. //--------------------------------------------------------------  GetPlayerInput
  283.  
  284. void GetPlayerInput (void)
  285. {
  286.     thePlayer.flapping = FALSE;
  287.     thePlayer.walking = FALSE;
  288.     
  289.     GetKeys(theKeys);
  290.     if (BitTst(&theKeys, kCommandKeyMap))
  291.         DoCommandKey();
  292.     else
  293.     {
  294.         if ((BitTst(&theKeys, kSpaceBarMap)) || (BitTst(&theKeys, kDownArrowKeyMap)))
  295.         {
  296.             if (thePlayer.mode == kIdle)
  297.             {
  298.                 thePlayer.mode = kWalking;
  299.                 thePlayer.frame = 0;
  300.             }
  301.             else if ((thePlayer.mode == kFlying) || (thePlayer.mode == kWalking))
  302.             {
  303.                 if (!flapKeyDown)
  304.                 {
  305.                     thePlayer.vVel -= kFlapImpulse;
  306.                     flapKeyDown = TRUE;
  307.                     PlayExternalSound(kFlapSound, kFlapPriority);
  308.                     thePlayer.flapping = TRUE;
  309.                 }
  310.             }
  311.         }
  312.         else
  313.             flapKeyDown = FALSE;
  314.         
  315.         if ((BitTst(&theKeys, kRightArrowKeyMap) || 
  316.                 BitTst(&theKeys, kSKeyMap) || 
  317.                 BitTst(&theKeys, kQuoteMap)) && 
  318.                 (thePlayer.hVel < kMaxHVelocity))
  319.         {
  320.             if (thePlayer.mode == kIdle)
  321.             {
  322.                 thePlayer.mode = kWalking;
  323.                 thePlayer.frame = 0;
  324.             }
  325.             else if ((thePlayer.mode == kFlying) || (thePlayer.mode == kWalking))
  326.             {
  327.                 if (!thePlayer.facingRight)
  328.                 {
  329.                     thePlayer.facingRight = TRUE;
  330.                     if (thePlayer.clutched)
  331.                     {
  332.                         thePlayer.dest.left += 18;
  333.                         thePlayer.dest.right += 18;                        
  334.                         thePlayer.h = thePlayer.dest.left << 4;
  335.                         thePlayer.wasH = thePlayer.h;
  336.                         thePlayer.wasDest = thePlayer.dest;
  337.                     }
  338.                 }
  339.                 else
  340.                 {
  341.                     if (thePlayer.mode == kFlying)
  342.                         thePlayer.hVel += kGlideImpulse;
  343.                     else
  344.                         thePlayer.walking = TRUE;
  345.                 }
  346.             }
  347.         }
  348.         else if ((BitTst(&theKeys, kLeftArrowKeyMap) || 
  349.                 BitTst(&theKeys, kAKeyMap) || 
  350.                 BitTst(&theKeys, kColonMap)) && 
  351.                 (thePlayer.hVel > -kMaxHVelocity))
  352.         {
  353.             if (thePlayer.mode == kIdle)
  354.             {
  355.                 thePlayer.mode = kWalking;
  356.                 thePlayer.frame = 0;
  357.             }
  358.             else if ((thePlayer.mode == kFlying) || (thePlayer.mode == kWalking))
  359.             {
  360.                 if (thePlayer.facingRight)
  361.                 {
  362.                     thePlayer.facingRight = FALSE;
  363.                     if (thePlayer.clutched)
  364.                     {
  365.                         thePlayer.dest.left -= 18;
  366.                         thePlayer.dest.right -= 18;
  367.                         thePlayer.h = thePlayer.dest.left << 4;
  368.                         thePlayer.wasH = thePlayer.h;
  369.                         thePlayer.wasDest = thePlayer.dest;
  370.                     }
  371.                 }
  372.                 else
  373.                 {
  374.                     if (thePlayer.mode == kFlying)
  375.                         thePlayer.hVel -= kGlideImpulse;
  376.                     else
  377.                         thePlayer.walking = TRUE;
  378.                 }
  379.             }
  380.         }
  381.     }
  382. }
  383.  
  384. //--------------------------------------------------------------  HandlePlayerIdle
  385.  
  386. void HandlePlayerIdle (void)
  387. {
  388.     thePlayer.frame--;
  389.     if (thePlayer.frame == 0)
  390.         thePlayer.mode = kWalking;
  391.     
  392.     SetAndCheckPlayerDest();
  393. }
  394.  
  395. //--------------------------------------------------------------  HandlePlayerFlying
  396.  
  397. void HandlePlayerFlying (void)
  398. {    
  399.     if (thePlayer.hVel > 0)
  400.     {
  401.         thePlayer.hVel -= kAirResistance;
  402.         if (thePlayer.hVel < 0)
  403.             thePlayer.hVel = 0;
  404.     }
  405.     else if (thePlayer.hVel < 0)
  406.     {
  407.         thePlayer.hVel += kAirResistance;
  408.         if (thePlayer.hVel > 0)
  409.             thePlayer.hVel = 0;
  410.     }
  411.     
  412.     thePlayer.vVel += kGravity;
  413.     
  414.     if (thePlayer.vVel > kMaxVVelocity)
  415.         thePlayer.vVel = kMaxVVelocity;
  416.     else if (thePlayer.vVel < -kMaxVVelocity)
  417.         thePlayer.vVel = -kMaxVVelocity;
  418.     
  419.     thePlayer.h += thePlayer.hVel;
  420.     thePlayer.v += thePlayer.vVel;
  421.     
  422.     if (thePlayer.facingRight)
  423.     {
  424.         thePlayer.srcNum = 1;
  425.         if (thePlayer.vVel < -kDontFlapVel)
  426.         {
  427.             if (thePlayer.flapping)
  428.                 thePlayer.srcNum = 0;
  429.             else
  430.                 thePlayer.srcNum = 1;
  431.         }
  432.         else if (thePlayer.vVel > kDontFlapVel)
  433.         {
  434.             if (thePlayer.flapping)
  435.                 thePlayer.srcNum = 1;
  436.             else
  437.                 thePlayer.srcNum = 0;
  438.         }
  439.         else if (thePlayer.flapping)
  440.             thePlayer.srcNum = 0;
  441.     }
  442.     else
  443.     {
  444.         thePlayer.srcNum = 2;
  445.         if (thePlayer.vVel < -kDontFlapVel)
  446.         {
  447.             if (thePlayer.flapping)
  448.                 thePlayer.srcNum = 3;
  449.             else
  450.                 thePlayer.srcNum = 2;
  451.         }
  452.         else if (thePlayer.vVel > kDontFlapVel)
  453.         {
  454.             if (thePlayer.flapping)
  455.                 thePlayer.srcNum = 2;
  456.             else
  457.                 thePlayer.srcNum = 3;
  458.         }
  459.         else if (thePlayer.flapping)
  460.             thePlayer.srcNum = 3;
  461.     }
  462.     
  463.     SetAndCheckPlayerDest();
  464.     
  465.     CheckLavaRoofCollision();
  466.     CheckPlayerEnemyCollision();
  467.     CheckPlatformCollision();
  468.     CheckTouchDownCollision();
  469. }
  470.  
  471. //--------------------------------------------------------------  HandlePlayerWalking
  472.  
  473. void HandlePlayerWalking (void)
  474. {
  475.     short        desiredHVel;
  476.     
  477.     if (thePlayer.walking)
  478.     {
  479.         if (evenFrame)
  480.         {
  481.             if (thePlayer.facingRight)
  482.             {
  483.                 if (thePlayer.srcNum == 4)
  484.                     desiredHVel = 208;
  485.                 else
  486.                     desiredHVel = 128;
  487.             }
  488.             else
  489.             {
  490.                 if (thePlayer.srcNum == 7)
  491.                     desiredHVel = -208;
  492.                 else
  493.                     desiredHVel = -128;
  494.             }
  495.             
  496.             if (thePlayer.hVel < desiredHVel)
  497.             {
  498.                 thePlayer.hVel += 80;
  499.                 if (thePlayer.hVel > desiredHVel)
  500.                 {
  501.                     thePlayer.hVel = desiredHVel;
  502.                     PlayExternalSound(kWalkSound, kWalkPriority);
  503.                 }
  504.                 else
  505.                     PlayExternalSound(kScreechSound, kScreechPriority);
  506.             }
  507.             else
  508.             {
  509.                 thePlayer.hVel -= 80;
  510.                 if (thePlayer.hVel < desiredHVel)
  511.                 {
  512.                     thePlayer.hVel = desiredHVel;
  513.                     PlayExternalSound(kWalkSound, kWalkPriority);
  514.                 }
  515.                 else
  516.                     PlayExternalSound(kScreechSound, kScreechPriority);
  517.             }
  518.         }
  519.     }
  520.     else
  521.     {
  522.         thePlayer.hVel -= thePlayer.hVel / 4;
  523.         if ((thePlayer.hVel < 4) && (thePlayer.hVel > -4))
  524.             thePlayer.hVel = 0;
  525.         else
  526.             PlayExternalSound(kScreechSound, kScreechPriority);
  527.     }
  528.     
  529.     if (thePlayer.vVel > kMaxVVelocity)
  530.         thePlayer.vVel = kMaxVVelocity;
  531.     else if (thePlayer.vVel < -kMaxVVelocity)
  532.         thePlayer.vVel = -kMaxVVelocity;
  533.     
  534.     thePlayer.h += thePlayer.hVel;
  535.     thePlayer.v += thePlayer.vVel;
  536.     
  537.     if (thePlayer.walking)
  538.     {
  539.         if (evenFrame)
  540.         {
  541.             if (thePlayer.facingRight)
  542.                 thePlayer.srcNum = 9 - thePlayer.srcNum;
  543.             else
  544.                 thePlayer.srcNum = 13 - thePlayer.srcNum;
  545.         }
  546.     }
  547.     else
  548.     {
  549.         if (thePlayer.facingRight)
  550.             thePlayer.srcNum = 5;
  551.         else
  552.             thePlayer.srcNum = 6;
  553.     }
  554.     
  555.     SetAndCheckPlayerDest();
  556.     
  557.     CheckTouchDownCollision();
  558.     KeepPlayerOnPlatform();
  559.     CheckPlayerEnemyCollision();
  560. }
  561.  
  562. //--------------------------------------------------------------  HandlePlayerSinking
  563.  
  564. void HandlePlayerSinking (void)
  565. {
  566.     thePlayer.hVel = 0;
  567.     thePlayer.vVel = 16;
  568.     if (thePlayer.dest.top > kLavaHeight)
  569.         OffAMortal();
  570.     
  571.     thePlayer.v += thePlayer.vVel;
  572.     
  573.     SetAndCheckPlayerDest();
  574. }
  575.  
  576. //--------------------------------------------------------------  HandlePlayerFalling
  577.  
  578. void HandlePlayerFalling (void)
  579. {
  580.     if (thePlayer.hVel > 0)
  581.     {
  582.         thePlayer.hVel -= kAirResistance;
  583.         if (thePlayer.hVel < 0)
  584.             thePlayer.hVel = 0;
  585.     }
  586.     else if (thePlayer.hVel < 0)
  587.     {
  588.         thePlayer.hVel += kAirResistance;
  589.         if (thePlayer.hVel > 0)
  590.             thePlayer.hVel = 0;
  591.     }
  592.     
  593.     thePlayer.vVel += kGravity;
  594.     
  595.     if (thePlayer.vVel > kMaxVVelocity)
  596.         thePlayer.vVel = kMaxVVelocity;
  597.     else if (thePlayer.vVel < -kMaxVVelocity)
  598.         thePlayer.vVel = -kMaxVVelocity;
  599.     
  600.     thePlayer.h += thePlayer.hVel;
  601.     thePlayer.v += thePlayer.vVel;
  602.     
  603.     SetAndCheckPlayerDest();
  604.     
  605.     CheckLavaRoofCollision();
  606.     CheckPlatformCollision();
  607. }
  608.  
  609. //--------------------------------------------------------------  HandlePlayerBones
  610.  
  611. void HandlePlayerBones (void)
  612. {
  613.     if (evenFrame)
  614.     {
  615.         thePlayer.frame--;
  616.         if (thePlayer.frame == 0)
  617.             OffAMortal();
  618.         else
  619.             thePlayer.dest.top = thePlayer.dest.bottom - thePlayer.frame;
  620.     }
  621. }
  622.  
  623. //--------------------------------------------------------------  MovePlayer
  624.  
  625. void MovePlayer (void)
  626. {
  627.     switch (thePlayer.mode)
  628.     {
  629.         case kIdle:
  630.         HandlePlayerIdle();
  631.         break;
  632.         
  633.         case kFlying:
  634.         HandlePlayerFlying();
  635.         break;
  636.         
  637.         case kWalking:
  638.         HandlePlayerWalking();
  639.         break;
  640.         
  641.         case kSinking:
  642.         HandlePlayerSinking();
  643.         break;
  644.         
  645.         case kFalling:
  646.         HandlePlayerFalling();
  647.         break;
  648.         
  649.         case kBones:
  650.         HandlePlayerBones();
  651.         break;
  652.     }
  653. }
  654.  
  655. //--------------------------------------------------------------  CheckTouchDownCollision
  656.  
  657. void CheckTouchDownCollision (void)
  658. {
  659.     Rect        testRect, whoCares;
  660.     short        i, offset;
  661.     Boolean        sected;
  662.     
  663.     sected = FALSE;
  664.     for (i = 0; i < numLedges; i++)
  665.     {
  666.         testRect = touchDownRects[i];
  667.         if (thePlayer.mode == kWalking)
  668.             OffsetRect(&testRect, 0, 11);
  669.         
  670.         if (SectRect(&thePlayer.dest, &testRect, &whoCares))
  671.         {
  672.             if (thePlayer.mode == kFlying)
  673.             {
  674.                 thePlayer.mode = kWalking;
  675.                 if (thePlayer.facingRight)
  676.                     thePlayer.srcNum = 5;
  677.                 else
  678.                     thePlayer.srcNum = 6;
  679.                 if (thePlayer.vVel > 0)
  680.                     thePlayer.vVel = 0;
  681.                 thePlayer.dest.bottom += 11;
  682.                 thePlayer.wasDest.bottom += 11;
  683.                 offset = thePlayer.dest.bottom - testRect.bottom - 1;
  684.                 thePlayer.dest.bottom -= offset;
  685.                 thePlayer.dest.top -= offset;
  686.                 thePlayer.v = thePlayer.dest.top << 4;
  687.                 PlayExternalSound(kGrateSound, kGratePriority);
  688.             }
  689.             sected = TRUE;
  690.         }
  691.     }
  692.     
  693.     if (!sected)
  694.     {
  695.         if (thePlayer.mode == kWalking)
  696.         {
  697.             thePlayer.mode = kFlying;
  698.             thePlayer.dest.bottom -= 11;
  699.             thePlayer.wasDest.bottom -= 11;
  700.         }
  701.     }
  702. }
  703.  
  704. //--------------------------------------------------------------  CheckPlatformCollision
  705.  
  706. void CheckPlatformCollision (void)
  707. {
  708.     Rect        hRect, vRect, whoCares;
  709.     short        i, offset;
  710.     
  711.     for (i = 0; i < numLedges; i++)
  712.     {
  713.         if (SectRect(&thePlayer.dest, &platformRects[i], &whoCares))
  714.         {
  715.             hRect.left = thePlayer.dest.left;
  716.             hRect.right = thePlayer.dest.right;
  717.             hRect.top = thePlayer.wasDest.top;
  718.             hRect.bottom = thePlayer.wasDest.bottom;
  719.             
  720.             if (SectRect(&hRect, &platformRects[i], &whoCares))
  721.             {
  722.                 if (thePlayer.h > thePlayer.wasH)            // heading right
  723.                 {
  724.                     offset = thePlayer.dest.right - platformRects[i].left;
  725.                     thePlayer.dest.left -= offset;
  726.                     thePlayer.dest.right -= offset;
  727.                     thePlayer.h = thePlayer.dest.left << 4;
  728.                     if (thePlayer.hVel > 0)
  729.                         thePlayer.hVel = -(thePlayer.hVel >> 1);
  730.                     else
  731.                         thePlayer.hVel = thePlayer.hVel >> 1;
  732.                 }
  733.                 else if (thePlayer.h < thePlayer.wasH)        // heading left
  734.                 {
  735.                     offset = platformRects[i].right - thePlayer.dest.left;
  736.                     thePlayer.dest.left += offset;
  737.                     thePlayer.dest.right += offset;
  738.                     thePlayer.h = thePlayer.dest.left << 4;
  739.                     if (thePlayer.hVel < 0)
  740.                         thePlayer.hVel = -(thePlayer.hVel >> 1);
  741.                     else
  742.                         thePlayer.hVel = thePlayer.hVel >> 1;
  743.                 }
  744.                 PlayExternalSound(kGrateSound, kGratePriority);
  745.             }
  746.             else
  747.             {
  748.                 vRect.left = thePlayer.wasDest.left;
  749.                 vRect.right = thePlayer.wasDest.right;
  750.                 vRect.top = thePlayer.dest.top;
  751.                 vRect.bottom = thePlayer.dest.bottom;
  752.                 
  753.                 if (SectRect(&vRect, &platformRects[i], &whoCares))
  754.                 {
  755.                     if (thePlayer.wasV < thePlayer.v)        // heading down
  756.                     {
  757.                         offset = thePlayer.dest.bottom - platformRects[i].top;
  758.                         thePlayer.dest.top -= offset;
  759.                         thePlayer.dest.bottom -= offset;
  760.                         thePlayer.v = thePlayer.dest.top << 4;
  761.                         if (thePlayer.vVel > kDontFlapVel)
  762.                             PlayExternalSound(kGrateSound, kGratePriority);
  763.                         if (thePlayer.mode == kFalling)
  764.                         {
  765.                             if ((thePlayer.dest.right - 16) > platformRects[i].right)                            {
  766.                                 thePlayer.hVel = 16;
  767.                                 if (thePlayer.vVel > 0)
  768.                                     thePlayer.vVel = -(thePlayer.vVel >> 1);
  769.                                 else
  770.                                     thePlayer.vVel = thePlayer.vVel >> 1;
  771.                             }
  772.                             else if ((thePlayer.dest.left + 16) < platformRects[i].left)
  773.                             {
  774.                                 thePlayer.hVel = -16;
  775.                                 if (thePlayer.vVel > 0)
  776.                                     thePlayer.vVel = -(thePlayer.vVel >> 1);
  777.                                 else
  778.                                     thePlayer.vVel = thePlayer.vVel >> 1;
  779.                             }
  780.                             else
  781.                             {
  782.                                 PlayExternalSound(kBoom1Sound, kBoom1Priority);
  783.                                 thePlayer.vVel = 0;
  784.                                 thePlayer.mode = kBones;
  785.                                 thePlayer.frame = 22;
  786.                                 thePlayer.dest.top = thePlayer.dest.bottom - 22;
  787.                                 thePlayer.v = thePlayer.dest.top << 4;
  788.                                 thePlayer.srcNum = 10;
  789.                             }
  790.                         }
  791.                         else
  792.                         {
  793.                             if (thePlayer.vVel > 0)
  794.                                 thePlayer.vVel = -(thePlayer.vVel >> 1);
  795.                             else
  796.                                 thePlayer.vVel = thePlayer.vVel >> 1;
  797.                         }
  798.                     }
  799.                     else if (thePlayer.wasV > thePlayer.v)    // heading up
  800.                     {
  801.                         offset = platformRects[i].bottom - thePlayer.dest.top;
  802.                         thePlayer.dest.top += offset;
  803.                         thePlayer.dest.bottom += offset;
  804.                         thePlayer.v = thePlayer.dest.top << 4;
  805.                         PlayExternalSound(kGrateSound, kGratePriority);
  806.                         if (thePlayer.vVel < 0)
  807.                             thePlayer.vVel = -(thePlayer.vVel >> 1);
  808.                         else
  809.                             thePlayer.vVel = thePlayer.vVel >> 1;
  810.                     }
  811.                 }
  812.             }
  813.         }
  814.     }
  815. }
  816.  
  817. //--------------------------------------------------------------  KeepPlayerOnPlatform
  818.  
  819. void KeepPlayerOnPlatform (void)
  820. {
  821.     Rect        whoCares;
  822.     short        i, offset;
  823.     
  824.     for (i = 0; i < numLedges; i++)
  825.     {
  826.         if ((SectRect(&thePlayer.dest, &platformRects[i], &whoCares)) && (thePlayer.vVel > 0))
  827.         {
  828.             offset = thePlayer.dest.bottom - platformRects[i].top - 1;
  829.             thePlayer.dest.top -= offset;
  830.             thePlayer.dest.bottom -= offset;
  831.             thePlayer.v = thePlayer.dest.top * 16;
  832.         }
  833.     }
  834.     
  835.     if (thePlayer.vVel > 0)
  836.         thePlayer.vVel = 0;
  837. }
  838.  
  839. //--------------------------------------------------------------  CheckLavaRoofCollision
  840.  
  841. void CheckLavaRoofCollision (void)
  842. {
  843.     short        offset;
  844.     
  845.     if (thePlayer.dest.bottom > kLavaHeight)
  846.     {
  847.         if (thePlayer.mode == kFalling)
  848.             PlayExternalSound(kSplashSound, kSplashPriority);
  849.         else
  850.             PlayExternalSound(kBirdSound, kBirdPriority);
  851.         thePlayer.mode = kSinking;
  852.     }
  853.     else if (thePlayer.dest.top < kRoofHeight)
  854.     {
  855.         offset = kRoofHeight - thePlayer.dest.top;
  856.         thePlayer.dest.top += offset;
  857.         thePlayer.dest.bottom += offset;
  858.         thePlayer.v = thePlayer.dest.top * 16;
  859.         PlayExternalSound(kGrateSound, kGratePriority);
  860.         thePlayer.vVel = thePlayer.vVel / -2;
  861.     }
  862. }
  863.  
  864. //--------------------------------------------------------------  SetAndCheckPlayerDest
  865.  
  866. void SetAndCheckPlayerDest (void)
  867. {
  868.     short        wasTall, wasWide;
  869.     
  870.     wasTall = thePlayer.dest.bottom - thePlayer.dest.top;
  871.     wasWide = thePlayer.dest.right - thePlayer.dest.left;
  872.     
  873.     thePlayer.dest.left = thePlayer.h >> 4;
  874.     thePlayer.dest.right = thePlayer.dest.left + wasWide;
  875.     thePlayer.dest.top = thePlayer.v >> 4;
  876.     thePlayer.dest.bottom = thePlayer.dest.top + wasTall;
  877.     
  878.     if (thePlayer.dest.left > 640)
  879.     {
  880.         OffsetRect(&thePlayer.dest, -640, 0);
  881.         thePlayer.h = thePlayer.dest.left << 4;
  882.         OffsetRect(&thePlayer.wasDest, -640, 0);
  883.     }
  884.     else if (thePlayer.dest.right < 0)
  885.     {
  886.         OffsetRect(&thePlayer.dest, 640, 0);
  887.         thePlayer.h = thePlayer.dest.left << 4;
  888.         OffsetRect(&thePlayer.wasDest, 640, 0);
  889.     }
  890. }
  891.  
  892. //--------------------------------------------------------------  HandleLightning
  893.  
  894. void HandleLightning (void)
  895. {
  896.     if (lightningCount > 0)
  897.     {
  898.         if (lightningCount == kNumLightningStrikes)
  899.             FlashObelisks(TRUE);
  900.         GenerateLightning(lightH, lightV);
  901.         StrikeLightning();
  902.     }
  903. }
  904.  
  905. //--------------------------------------------------------------  FinishLightning
  906.  
  907. void FinishLightning (void)
  908. {
  909.     if (lightningCount > 0)
  910.     {
  911.         StrikeLightning();
  912.         lightningCount--;
  913.         if (lightningCount == 0)
  914.             FlashObelisks(FALSE);
  915.         PlayExternalSound(kLightningSound, kLightningPriority);
  916.     }
  917. }
  918.  
  919. //--------------------------------------------------------------  HandleCountDownTimer
  920.  
  921. void HandleCountDownTimer (void)
  922. {
  923.     if (countDownTimer == 0)
  924.         return;
  925.     else
  926.     {
  927.         countDownTimer--;
  928.         if (countDownTimer == 0)
  929.         {
  930.             countDownTimer = 0;
  931.             levelOn++;
  932.             UpdateLevelNumbers();
  933.             SetUpLevel();
  934.             GenerateEnemies();
  935.         }
  936.     }
  937. }
  938.  
  939. //--------------------------------------------------------------  PlayGame
  940.  
  941. void PlayGame (void)
  942. {
  943.     #define        kTicksPerFrame        2L
  944.     Point        offsetPt;
  945.     long        waitUntil;
  946.     
  947.     offsetPt.h = 0;
  948.     offsetPt.v = 20;
  949.     ShieldCursor(&mainWindowRect, offsetPt);
  950.     waitUntil = TickCount() + kTicksPerFrame;
  951.     
  952.     do
  953.     {    
  954.         MovePlayer();
  955.         MoveEnemies();
  956.         HandleHand();
  957.         HandleEye();
  958.         DrawFrame();
  959.         HandleLightning();
  960.         do
  961.         {
  962.         } while (TickCount() < waitUntil);
  963.         waitUntil = TickCount() + kTicksPerFrame;
  964.         evenFrame = !evenFrame;
  965.         
  966.         GetPlayerInput();
  967.         HandleCountDownTimer();
  968.         FinishLightning();
  969.     }
  970.     while ((playing) && (!pausing));
  971.     
  972.     if ((!playing) && (!quitting))
  973.     {
  974.         PlayExternalSound(kMusicSound, kMusicPriority);
  975.         CheckHighScore();
  976.     }
  977.     
  978.     ShowCursor();
  979.     MenusReflectMode();
  980.     FlushEvents(everyEvent, 0);
  981. }
  982.  
  983. //--------------------------------------------------------------  CheckHighScore
  984.  
  985. void CheckHighScore (void)
  986. {
  987.     #define        kHighNameDialogID    130
  988.     Str255        placeStr, tempStr;
  989.     DialogPtr    theDial;
  990.     short        i, item;
  991.     Boolean        leaving;
  992.     
  993.     if (theScore > thePrefs.highScores[9])
  994.     {
  995.         openTheScores = TRUE;
  996.         
  997.         PlayExternalSound(kBonusSound, kMusicPriority - 1);
  998.         i = 8;
  999.         while ((theScore > thePrefs.highScores[i]) && (i >= 0))
  1000.         {
  1001.             thePrefs.highScores[i + 1] = thePrefs.highScores[i];
  1002.             thePrefs.highLevel[i + 1] = thePrefs.highLevel[i];
  1003.             PasStringCopy(thePrefs.highNames[i], thePrefs.highNames[i + 1]);
  1004.             i--;
  1005.         }
  1006.         
  1007.         i++;
  1008.         thePrefs.highScores[i] = theScore;
  1009.         thePrefs.highLevel[i] = levelOn + 1;
  1010.         
  1011.         NumToString((long)i + 1L, placeStr);
  1012.         ParamText(placeStr, "\p", "\p", "\p");
  1013.         
  1014.         InitCursor();
  1015.         CenterDialog(kHighNameDialogID);
  1016.         theDial = GetNewDialog(kHighNameDialogID, 0L, kPutInFront);
  1017.         SetPort((GrafPtr)theDial);
  1018.         ShowWindow((GrafPtr)theDial);
  1019.         DrawDefaultButton(theDial);
  1020.         FlushEvents(everyEvent, 0);
  1021.         SetDialogString(theDial, 2, thePrefs.highName);
  1022.         SelIText(theDial, 2, 0, 1024);
  1023.         leaving = FALSE;
  1024.         
  1025.         while (!leaving)
  1026.         {
  1027.             ModalDialog(0L, &item);
  1028.             
  1029.             if (item == 1)
  1030.             {
  1031.                 GetDialogString(theDial, 2, tempStr);
  1032.                 PasStringCopyNum(tempStr, thePrefs.highNames[i], 15);
  1033.                 PasStringCopy(thePrefs.highNames[i], thePrefs.highName);
  1034.                 leaving = TRUE;
  1035.             }
  1036.         }
  1037.         
  1038.         DisposDialog(theDial);
  1039.     }
  1040.     else
  1041.         openTheScores = FALSE;
  1042. }
  1043.  
  1044.